<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>{$Think.config.site.title} - 供应商添加商品</title>
    <meta name="keywords" content="{$Think.config.site.keywords}">
    <meta name="description" content="{$Think.config.site.description}">

    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.min.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.min.css?v=4.0.0" rel="stylesheet">
    <style type="text/css">
    	.text-c{text-align: center;}
    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
      <form method="get" class="form-horizontal">
      <div class="row">
          	<div class="col-sm-7">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>商品信息</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                      	</div>
                    </div>
                    <div class="ibox-content">
                        
                        <input type="hidden" name="brand_id" value="" />
                      
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品名称</label>
                                <div class="col-sm-9">
                                    <input  class="form-control" type="text" value="{$goods.goods_name}" disabled="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品品牌</label>
                                <div class="col-sm-9">
                                    <input class="form-control" type="text" value="{$goods.brand_name}" disabled="true">

                                </div>
                            </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-5">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>商品图片</h5> 
						<div class="ibox-tools">
							<a class="collapse-link">
							<i class="fa fa-chevron-up"></i>
							</a>
						</div>
					</div>
					<div class="ibox-content">
						<p><img  alt="image"  src="{$goods.picture}" style="max-width: 100%;" /></p>
					</div>
				</div>
          </div>
        </div>
        <div class="row">
        	<div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>商品规格列表 【{$supplier.supplier_name} {$supplier.remark}】</h5>
                        <span class="tag"></span>
                    </div>
                    <div class="ibox-content">
                        <div class="table-responsive">
                            <table class="table table-striped" id="listtable">
                                <thead>
                                    <tr>
                                    	<th width="100" class="text-c">上架</th>
                                        <th >规格名称</th>
                                        <th >价格</th>
                                        
                                    </tr>
                                </thead>
                                <tbody>

                                	{volist name="sval" id="vo"}
                                    <tr class="sval" data-id="{$goods.goods_id}" data-specval_id='{$vo.specval_id}' data-specval_pid='{$vo.specval_pid}'  >
                                    	<td class="text-c">
                                        	<input name="ids[]"  type="checkbox" class="i-checks" value="{$vo.specval_id}" {if($vo['checked'])} checked="true" {/if}>
                                        </td>
                                        <td>{$vo.specval_name}</td>
                                        <td>
                                        	<input class="form-control" type="text" name="price" {if(!$vo['checked'])} disabled="true" {/if} value="{$vo.price}">
                                        </td>
                                    </tr>
                                   {/volist}

                                </tbody>
                            </table>
                        </div>
                    </div>
                    
                </div>
            </div>
        </div>
        <div class="row">
        	<div class="col-sm-12" style="text-align: right;">
        		<button class="btn btn-primary" id="save" style="width: 200px" type="button">保存</button>
        	</div>
        </div>
        </form>
    </div>

    <script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
    <script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
    <script src="{$Think.config.site.resource_url}js/content.min.js?v=1.0.0"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/validate/jquery.validate.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/validate/messages_zh.min.js"></script>
  	<script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
  	<script src="{$Think.config.site.resource_url}js/plugins/iCheck/icheck.min.js"></script>
  	<script src="{$Think.config.site.common_resource_url}js/majax.js"></script>
  	<script src="{$Think.config.site.common_resource_url}js/laydate/laydate.js"></script>
</body>

</html>
<script>


$(document).ready(function(){

	$('input[name="ids[]"]').iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});

	$('input[name="ids[]"]').on('ifChecked',function(){
		$(this).closest('tr').find('input[name="price"]').attr('disabled',false);
	})

	$('input[name="ids[]"]').on('ifUnchecked',function(){
		$(this).closest('tr').find('input[name="price"]').attr('disabled',true);
	})


	$('#save').click(function(){
		var list = [];error=false;
		$('#listtable .sval').each(function(){
			var price = $(this).find('input[name="price"]').val();
			if (isNaN(price)) {
				$(this).find('input[name="price"]').focus();
				layer.msg('价格必须为数字',{icon:2});
				error=true;
				return false;
			}
			list.push({
				'specval_id' : $(this).data('specval_id'),
				'price' : price,
				'check' : $(this).find('input[name="ids[]"]').is(':checked')
			})
		})

		if (error) {return;}
		majax('{:url("addgoods",["supplierid"=>$supplier["supplier_id"]])}',{sval:list},function(d){
			if (d.code>0) {
				window.parent.editSuccess(d);
			}else{
				layer.msg(d.msg, {icon: 5});
			}
		})
	})
})
</script>